<?php

/**
 * @author @author Samrat Khan & Sadik Sarfaraz - Apr 13, 2013
 */
require('top.inc.php');

if(isset($_SESSION['user']) && $_SESSION['user']['utype'] == 1 || $_SESSION['user']['utype'] == 2 || $_SESSION['user']['utype'] == 3 || $_SESSION['user']['utype'] == 4) {
    $sess_cusID = $_SESSION['user']['cus_id'];

    //create new object pass in number of pages and identifier
    $pages = new Paginator(' 50', 'page');
    $total = getCountA('stockin', 'stockin_id', 'cus_id', $sess_cusID, $db);
    $tots = $total[0]['total'];
    $totals = $pages->set_total($tots);
    $limit = $pages->get_limit();
    // for stock in hand count
    $totalmatch = getCountMatchColumn('stockin', 'stockout', 'serialno', 'serialno', 'cus_id', $sess_cusID, $db);
    $matchtots = $totalmatch[0]['total'];
	
	$rows = selectAllWhereA('stockin', $limit, 'cus_id', $sess_cusID, $db);

    
    echo '<div class="fixedleftBox">';
        echo "<input class=\"btn btn-primary\" type=\"button\" onclick=\"tableToExcel('stockindiv', 'Stockin')\" value=\"Export to excel\">";
    echo '</div>';
    
    echo "<table id=\"stockindiv\" class=\"row-fluid table table-striped table-bordered\">";
            echo "<tr>";
                echo "<th>". $stock_in['serialno'] ."</th>";
                echo "<th>". $stock_in['project_id'] ."</th>";
                echo "<th>". $stock_in['productid'] ."</th>";
                echo "<th>". $stock_in['description'] ."</th>";
                echo "<th>". $stock_in['revisionstate'] ."</th>";
                echo "<th>". $stock_in['in_quantity'] ."</th>";
                echo "<th>". $stock_in['uom'] ."</th>";
                echo "<th>". $stock_in['shiptype'] ."</th>";
                echo "<th>". $stock_in['invoicenumber'] ."</th>";
                echo "<th>". $stock_in['ship_no'] ."</th>";
                echo "<th>". $stock_in['mawb'] ."</th>";
                echo "<th>". $stock_in['hawb'] ."</th>";
                echo "<th>". $stock_in['receiveddate'] ."</th>";
                echo "<th>". $stock_in['shipfrom'] ."</th>";
                echo "<th>". $stock_in['boxno'] ."</th>";
                echo "<th>". $stock_in['rma'] ."</th>";
                echo "<th>". $stock_in['warehouse_name'] ."</th>";
                echo "<th>". $stock_in['rackno'] ."</th>";
                echo "<th>". $stock_in['docketnumber'] ."</th>";
                echo "<th>". $stock_in['remarks'] ."</th>";
                echo "<th>". $stock_in['userid'] ."</th>";
                echo "<th>". $stock_in['cus_id'] ."</th>";
                echo "<th>". $stock_in['inserteddate'] ."</th>";
            echo "</tr>";
        foreach ($rows as $row) {
            echo "<tr>";
                echo "<td>". $row['serialno'] ."</td>";
                echo "<td>";
                    echo getName('projects', 'projectname', 'project_id', $row['project_id'], $db);
                    echo "<br/>";
                    $idofcustomer = getName('projects', 'cus_id', 'project_id', $row['project_id'], $db);
                    $customerid = getName('customerinfo', 'cus_id', 'cus_id', $idofcustomer, $db);
                echo "</td>";
                echo "<td>". $row['productid'] ."</td>";
                echo "<td>". $row['description'] ."</td>";
                echo "<td>". $row['revisionstate'] ."</td>";
                echo "<td>". $row['in_quantity'] ."</td>";
                echo "<td>". getName('uom', 'measurement', 'uom_id', $row['uom'], $db) ."</td>";
                echo "<td>". getName('shiptype', 'typename', 'shiptype_id', $row['shiptype'], $db) ."</td>";
                echo "<td>". $row['invoicenumber'] ."</td>";
                echo "<td>". $row['shipid'] ."</td>";
                echo "<td>". $row['mawb'] ."</td>";
                echo "<td>". $row['hawb'] ."</td>";
                echo "<td>". $row['receiveddate'] ."</td>";
                echo "<td>". $row['shipfrom'] ."</td>";
                echo "<td>". $row['boxno'] ."</td>";
                echo "<td>". $row['rma'] ."</td>";
                echo "<td>". getName('warehouses', 'warehousename', 'warehouse_id', $row['warehouse_id'], $db) ."</td>";
                echo "<td>". $row['rackno'] ."</td>";
                echo "<td>". $row['docketnumber'] ."</td>";
                echo "<td>". $row['remarks'] ."</td>";
                echo "<td>". getName('wms_users', 'username', 'id', $row['userid'], $db) ."</td>";
                echo "<td>". getName('customerinfo', 'cusname', 'cus_id', $row['cus_id'], $db) ."</td>";
                echo "<td>". $row['inserteddate'] ."</td>";
            echo "</tr>";
        }
    echo "<table>";
    echo $pages->page_links();
} else {
    header("Location: login.php");
}
include ('bottom.inc.php');
?>